﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

public partial class User_UserIndex : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
             string username = "";

            if (Session["userName"] != null)
            {
                SqlDataSource1.SelectCommand = "declare @username varchar(50)"+
                "declare @bookID varchar(50)" +
                "declare @userID varchar(50)" +
                "declare @bookInfo varchar(50)" +
                "select @userID=Reader_info.ReaderID from Reader_info where Reader_info.ReaderID=@name " +
                "select @bookID=Borrow_books_manage.BookID from Borrow_books_manage where Borrow_books_manage.readerID=@userID " +
                "select Book_info.BookID  as 图书编号,Book_info.BookName as 图书条目,Book_info.FindBookNum as 索书号,Book_info.Writer as 作者,Book_info.BookPlace as 馆藏地点,Borrow_books_manage.LendBookDate as 借书日期,Borrow_books_manage.ShouldReturnDate as 应还日期," +
                "Book_info.Price as 价格,Borrow_books_manage.XUJIETIMES as 续借次数 from Book_info , Borrow_books_manage where Borrow_books_manage.readerID=@userID and Borrow_books_manage.bookid=Book_info.bookid and returndate is null";
                SqlDataSource1.SelectParameters["name"].DefaultValue = Session["userName"].ToString();
                
            }

    }
    protected void sureBorrowAgain_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string bookID = cell[1].Text;
                SQL sql=new SQL();
                string readerID = Session["userName"].ToString();
                bool flag = sql.BorrowAgain(readerID, bookID);
                if (flag)
                {
                    Response.Write("<script language=javascript>alert('续借成功');window.location = 'UserIndex.aspx';</script>");
                    
                }
                else
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('您已经达到了最大续借次数')", true); 
               
            }
           
        }

       

    }
    protected void Cancel_Click(object sender, EventArgs e)
    {

    }

    protected void chaxun_Click(object sender, EventArgs e)
    {

    }
}